<?php include "lang.php"; ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<?php include "import.php"; ?>
	<script type="text/javascript">
	$(document).ready(function() {
		$('div.image_box').each(
			function(column) {
				$(this).click(function(event){
					var selectedNodes = getCookie('selectedNodes');
					selectedNodes += "," + this.id;
					setCookie('selectedNodes', selectedNodes, 30);
				}); 
			}
		);
	});
	</script>
	<title>Gia An</title>
</head>
<body onunload="unloadP('productPageScroll')" onload="loadP('productPageScroll')">
	<?php include("floating-panel.php"); ?>
	<div class="wrapper">

	<?php include("header.php"); ?>
		<div class="main_body">
			
			<?php include("left_menu.php")?>
			<div class="main_content">
				<div class="main_content_header"><?php echo $langs['category.category']?></div>
				<?php 
					
					function buildCategoryBox($category) {
						echo ("<div class='image_box' id='cat_" . $category['CAT_ID'] . "'>");
						echo ("<a href='" . (hasProduct($category['CAT_ID']) ? "product.php?catId=" : "category.php?catId=") . $category['CAT_ID'] . "'>");
						echo ("<div class='image_wrapper background'><img src='../images/cat/" . $category['CAT_IMG_URL'] . "' width='88' height='188'/></div>");
						echo ("<div class='image_wrapper'><img src='../images/cat/" . $category['CAT_IMG_URL'] . "' width='188' height='188'/></div>");
						echo ("</a>");
						echo ("</div>");
					}
					
					$current_page = isset($_REQUEST['page']) ? $_REQUEST['page'] : 1;
					
					$catId =  isset($_REQUEST['catId']) ? $_REQUEST['catId'] : -1;
					
					$row_per_page = 9;
						
					$catCount = countChildCategory($catId);
					$total_page = ceil($catCount / $row_per_page);
					$start_position = ($current_page * $row_per_page) - $row_per_page;
						
					$categories = getChildrenCategoryOf($catId, $start_position, $row_per_page);
					if ($categories) {
						while($row = mysql_fetch_array($categories)) {
							buildCategoryBox($row);
						}
					}
				?>
				<div class='paging'>
					<span class="prn">&lt;&lt;</span>
					<?php 
						
					for ($i = 1; $i <= $total_page; $i++)
					{
						if ($i == $current_page) {
							echo "<span>$i</span>";
						} else {
							echo "<a href='category.php?&catId=$catId&page=$i'>$i</a>";
						}
					}
					?>			
					<span class="prn">&gt;&gt;</span>
				</div>
				

			</div>
		</div>
        </div>
    <?php include("footer.php");?>
</body>
</html>
